/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.portlet.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.portlet.service.ClpSerializer;
import com.portlet.service.nlhasspLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Thi
 */
public class nlhasspClp extends BaseModelImpl<nlhassp> implements nlhassp {
	public nlhasspClp() {
	}

	public Class<?> getModelClass() {
		return nlhassp.class;
	}

	public String getModelClassName() {
		return nlhassp.class.getName();
	}

	public long getPrimaryKey() {
		return _maNLSP;
	}

	public void setPrimaryKey(long primaryKey) {
		setMaNLSP(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_maNLSP);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("maNLSP", getMaNLSP());
		attributes.put("maNguyenLieu", getMaNguyenLieu());
		attributes.put("maQC", getMaQC());
		attributes.put("quyCach", getQuyCach());
		attributes.put("tieuChiKiemTra", getTieuChiKiemTra());
		attributes.put("cachKiemTra", getCachKiemTra());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long maNLSP = (Long)attributes.get("maNLSP");

		if (maNLSP != null) {
			setMaNLSP(maNLSP);
		}

		String maNguyenLieu = (String)attributes.get("maNguyenLieu");

		if (maNguyenLieu != null) {
			setMaNguyenLieu(maNguyenLieu);
		}

		String maQC = (String)attributes.get("maQC");

		if (maQC != null) {
			setMaQC(maQC);
		}

		String quyCach = (String)attributes.get("quyCach");

		if (quyCach != null) {
			setQuyCach(quyCach);
		}

		String tieuChiKiemTra = (String)attributes.get("tieuChiKiemTra");

		if (tieuChiKiemTra != null) {
			setTieuChiKiemTra(tieuChiKiemTra);
		}

		String cachKiemTra = (String)attributes.get("cachKiemTra");

		if (cachKiemTra != null) {
			setCachKiemTra(cachKiemTra);
		}
	}

	public long getMaNLSP() {
		return _maNLSP;
	}

	public void setMaNLSP(long maNLSP) {
		_maNLSP = maNLSP;

		if (_nlhasspRemoteModel != null) {
			try {
				Class<?> clazz = _nlhasspRemoteModel.getClass();

				Method method = clazz.getMethod("setMaNLSP", long.class);

				method.invoke(_nlhasspRemoteModel, maNLSP);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getMaNguyenLieu() {
		return _maNguyenLieu;
	}

	public void setMaNguyenLieu(String maNguyenLieu) {
		_maNguyenLieu = maNguyenLieu;

		if (_nlhasspRemoteModel != null) {
			try {
				Class<?> clazz = _nlhasspRemoteModel.getClass();

				Method method = clazz.getMethod("setMaNguyenLieu", String.class);

				method.invoke(_nlhasspRemoteModel, maNguyenLieu);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getMaQC() {
		return _maQC;
	}

	public void setMaQC(String maQC) {
		_maQC = maQC;

		if (_nlhasspRemoteModel != null) {
			try {
				Class<?> clazz = _nlhasspRemoteModel.getClass();

				Method method = clazz.getMethod("setMaQC", String.class);

				method.invoke(_nlhasspRemoteModel, maQC);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getQuyCach() {
		return _quyCach;
	}

	public void setQuyCach(String quyCach) {
		_quyCach = quyCach;

		if (_nlhasspRemoteModel != null) {
			try {
				Class<?> clazz = _nlhasspRemoteModel.getClass();

				Method method = clazz.getMethod("setQuyCach", String.class);

				method.invoke(_nlhasspRemoteModel, quyCach);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getTieuChiKiemTra() {
		return _tieuChiKiemTra;
	}

	public void setTieuChiKiemTra(String tieuChiKiemTra) {
		_tieuChiKiemTra = tieuChiKiemTra;

		if (_nlhasspRemoteModel != null) {
			try {
				Class<?> clazz = _nlhasspRemoteModel.getClass();

				Method method = clazz.getMethod("setTieuChiKiemTra",
						String.class);

				method.invoke(_nlhasspRemoteModel, tieuChiKiemTra);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public String getCachKiemTra() {
		return _cachKiemTra;
	}

	public void setCachKiemTra(String cachKiemTra) {
		_cachKiemTra = cachKiemTra;

		if (_nlhasspRemoteModel != null) {
			try {
				Class<?> clazz = _nlhasspRemoteModel.getClass();

				Method method = clazz.getMethod("setCachKiemTra", String.class);

				method.invoke(_nlhasspRemoteModel, cachKiemTra);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getnlhasspRemoteModel() {
		return _nlhasspRemoteModel;
	}

	public void setnlhasspRemoteModel(BaseModel<?> nlhasspRemoteModel) {
		_nlhasspRemoteModel = nlhasspRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _nlhasspRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_nlhasspRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			nlhasspLocalServiceUtil.addnlhassp(this);
		}
		else {
			nlhasspLocalServiceUtil.updatenlhassp(this);
		}
	}

	@Override
	public nlhassp toEscapedModel() {
		return (nlhassp)ProxyUtil.newProxyInstance(nlhassp.class.getClassLoader(),
			new Class[] { nlhassp.class }, new AutoEscapeBeanHandler(this));
	}

	public nlhassp toUnescapedModel() {
		return this;
	}

	@Override
	public Object clone() {
		nlhasspClp clone = new nlhasspClp();

		clone.setMaNLSP(getMaNLSP());
		clone.setMaNguyenLieu(getMaNguyenLieu());
		clone.setMaQC(getMaQC());
		clone.setQuyCach(getQuyCach());
		clone.setTieuChiKiemTra(getTieuChiKiemTra());
		clone.setCachKiemTra(getCachKiemTra());

		return clone;
	}

	public int compareTo(nlhassp nlhassp) {
		long primaryKey = nlhassp.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof nlhasspClp)) {
			return false;
		}

		nlhasspClp nlhassp = (nlhasspClp)obj;

		long primaryKey = nlhassp.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(13);

		sb.append("{maNLSP=");
		sb.append(getMaNLSP());
		sb.append(", maNguyenLieu=");
		sb.append(getMaNguyenLieu());
		sb.append(", maQC=");
		sb.append(getMaQC());
		sb.append(", quyCach=");
		sb.append(getQuyCach());
		sb.append(", tieuChiKiemTra=");
		sb.append(getTieuChiKiemTra());
		sb.append(", cachKiemTra=");
		sb.append(getCachKiemTra());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(22);

		sb.append("<model><model-name>");
		sb.append("com.portlet.model.nlhassp");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>maNLSP</column-name><column-value><![CDATA[");
		sb.append(getMaNLSP());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>maNguyenLieu</column-name><column-value><![CDATA[");
		sb.append(getMaNguyenLieu());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>maQC</column-name><column-value><![CDATA[");
		sb.append(getMaQC());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>quyCach</column-name><column-value><![CDATA[");
		sb.append(getQuyCach());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>tieuChiKiemTra</column-name><column-value><![CDATA[");
		sb.append(getTieuChiKiemTra());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>cachKiemTra</column-name><column-value><![CDATA[");
		sb.append(getCachKiemTra());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _maNLSP;
	private String _maNguyenLieu;
	private String _maQC;
	private String _quyCach;
	private String _tieuChiKiemTra;
	private String _cachKiemTra;
	private BaseModel<?> _nlhasspRemoteModel;
}